package com.cloud.controller;

import com.cloud.entity.CommonResult;
import com.cloud.entity.Payment;
import com.cloud.service.PaymentHystrixFeignService;
import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * <h3>springcloud02</h3>
 * <p></p>
 *
 * @author : zhengyue
 * @date : 2020-06-03 08:16
 **/
@RestController
@DefaultProperties(defaultFallback = "paymentInfoGlobalFallbackMethod")
public class OrderHystrixFeignController {

    @Autowired
    private PaymentHystrixFeignService paymentHystrixFeignService;

    @GetMapping("/consumer/payment/hystrix/ok/{id}")
    public String paymentInfo_OK(@PathVariable("id") Integer id) {
        return paymentHystrixFeignService.paymentInfo_OK(id);
    }

    @GetMapping("/consumer/payment/hystrix/timeout/{id}")
//    @HystrixCommand(fallbackMethod = "paymentInfoTimeOutHandler", commandProperties = {
//            @HystrixProperty(name ="execution.isolation.thread.timeoutInMilliseconds", value = "3000")
//    })
    @HystrixCommand
    public String paymentInfoTimeout(@PathVariable("id") Integer id) {
        return paymentHystrixFeignService.paymentInfo_Timeout(id);
    }

    public String paymentInfoTimeOutHandler(@PathVariable("id") Integer id) {
        return "我是消费者80，对方支付系统繁忙，请稍后再试，/(ㄒoㄒ)/~~";
    }

    //全局fallback
    public String paymentInfoGlobalFallbackMethod() {
        return "Global异常处理信息，对方支付系统繁忙，请稍后再试，/(ㄒoㄒ)/~~";
    }
}
